<template>
  <div id="app">
    <router-view v-if="isRouterAlive"></router-view>
  </div>
</template>

<script>
  export default {
    name: 'App',
    provide() {
      return {
        reload: this.reload
      }
    },
    data() {
      return {
        isRouterAlive: true
      }
    },
    created() {
      window.addEventListener('beforeunload', () => {
        localStorage.setItem('messageStore', JSON.stringify(this.$store.state))
      })
      localStorage.getItem('messageStore') && this.$store.replaceState(Object.assign(this.$store.state, JSON.parse(
        localStorage.getItem('messageStore'))))
    },
    methods: {
      reload() {
        this.isRouterAlive = false
        this.$nextTick(function() {
          this.isRouterAlive = true
        })
      }
    }
  }
</script>
<style>
  ::-webkit-scrollbar {
    width: 4px;
    height: 8px;
  }

  ::-webkit-scrollbar-thumb {
    border-radius: 10px;
    background: deepskyblue;
  }

  ::-webkit-scrollbar-track {
    border-radius: 0;
    background: rgb(240, 240, 240);
  }
</style>
